<script setup lang="ts">
import { ref, onMounted } from 'vue'
// 引入顶部子组件
import Top from '@/views/screen/components/top/index.vue'
// 引入左侧三个子组件
import Tourist from '@/views/screen/components/tourist/index.vue'
import Gender from '@/views/screen/components/gender/index.vue'
import Age from '@/views/screen/components/age/index.vue'
// 获取数据大屏内容例子的DOM元素
let screen = ref()

onMounted(() => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`

  console.log(getScale())
})

// 大屏绽放比例
function getScale(w = 1920, h = 1080) {
  const windowWidth = window.innerWidth / w
  const windowHeight = window.innerHeight / h
  return windowWidth < windowHeight ? windowWidth : windowHeight
}

// 监听视口变化
window.onresize = () => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`
}
</script>

<template>
  <div class="container">
    <!--  数据大屏展示内容区域-->
    <div class="screen" ref="screen">
      <!--      数据大屏顶部-->
      <div class="top"><Top /></div>
      <div class="bottom">
        <div class="left">
          <Tourist class="tourist"></Tourist>
          <Gender class="gender"></Gender>
          <Age class="age"></Age>
        </div>
        <div class="center">中间</div>
        <div class="right">右侧</div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: url('./images/bg.png') no-repeat;
  background-size: cover;

  .screen {
    position: fixed;
    width: 1920px;
    height: 1080px;
    left: 50%;
    top: 50%;
    transform-origin: left top;
    .top {
      width: 100%;
      height: 40px;
    }

    .bottom {
      display: flex;

      .left {
        flex: 1;
        height: 1040px;
        display: flex;
        flex-direction: column;

        .tourist {
          flex: 1.2;
        }
        .gender {
          flex: 1;
          background-color: orange;
        }
        .age {
          flex: 1;
          background-color: white;
        }
      }
      .center {
        flex: 2;
      }

      .right {
        flex: 1;
      }
    }
  }
}
</style>
